clear all
set(0,'DefaultFigureWindowStyle','docked')

%% load data

data = xlsread('plot_data.xlsx');
% fields: year	mu3_1y	mu3_5y	dU_1y	dU_5y

year = data(:,1);
mu3_1y = data(:,2);
mu3_5y = data(:,3);
dU_1y = data(:,4);
dU_5y = data(:,5);

%% correlations

corr_1y = corr(mu3_1y,dU_1y);

IDX = find(~isnan(mu3_5y) & ~isnan(dU_5y));
corr_5y = corr(mu3_5y(IDX),dU_5y(IDX));

fprintf('corr 1y=%g\n',corr_1y)
fprintf('corr 5y=%g\n',corr_5y)

%% plot

LineWidth = 2;
FontSize = 20;

figure

subplot(1,2,1)
hold on
yyaxis left
plot(year, mu3_1y, '-b', 'LineWidth', LineWidth)
ylabel('$\mu_3$, 1y','FontSize', FontSize, 'Interpreter','latex')
yyaxis right
plot(year, dU_1y, ':sr', 'LineWidth', LineWidth)
ylabel('$\Delta U$, 1y','FontSize', FontSize, 'Interpreter','latex')
set(gca,'xlim',[1979 2011])

title(['A. $\mu_3$ vs. $\Delta U$, 1y. $\rho=',num2str(round(corr_1y,2)),'$'],'FontSize', FontSize, 'Interpreter','latex')

box on

subplot(1,2,2)
hold on
yyaxis left
plot(year(IDX), mu3_5y(IDX), '-b', 'LineWidth', LineWidth)
ylabel('$\mu_3$, 5y','FontSize', FontSize, 'Interpreter','latex')
yyaxis right
plot(year(IDX), dU_5y(IDX), ':sr', 'LineWidth', LineWidth)
ylabel('$\Delta U$, 5y','FontSize', FontSize, 'Interpreter','latex')
set(gca,'xlim',[1979 2011])

title(['B. $\mu_3$ vs. $\Delta U$, 5y. $\rho=',num2str(round(corr_5y,2)),'$'],'FontSize', FontSize, 'Interpreter','latex')

box on